import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public class StopWatchFunctionality {
	private int hour;
	private int minute;
	private int second;
	private int millisecond;
	private Timer timer;
	
	public StopWatchFunctionality(){
		
		timer = new Timer(1,new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				millisecond+=1;
				checkMillisecond();
				//update display
				StopWatchGui.updateDisplay();
				
			}});
	}//End of no-arg constructor
	
	private void checkMillisecond(){
		if(millisecond>=1000){
			millisecond = 0;
			second+=1;
			checkSecond();
			
		}
	}
	
	private void checkSecond(){
		if(second>=60){
			second = 0;
			minute+=1;
			checkMinute();
		}
	}
	
	private void checkMinute(){
		if(minute>=60){
			minute = 0;
			hour+=1;
		}
	}
	
	public void start(){
		timer.start();
	}
	
	public void stop(){
		timer.stop();
	}
	
	public void reset(){
		millisecond = 0;
		second = 0;
		minute = 0;
		hour = 0;
	}
	
	public int getMillisecond() {
		return millisecond;
	}
	
	public int getSecond(){
		return second;
	}
	
	public int getMinute(){
		return minute;
	}
	
	public int getHour(){
		return hour;
	}

}//End of class
